import { choice, choicePublish } from '@/api/hmmm/questions.js'
import { simple } from '@/api/hmmm/subjects.js'
import * as dire from '@/api/hmmm/directorys.js'
import * as tags from '@/api/hmmm/tags.js'
import * as users from '@/api/base/users.js'
const questionsChoice = {

  state: {
    QuestinosChoiceLists: [],
    objectLists: [],
    catalog: [],
    tagsList: [],
    userlist: []
  },
  mutations: {
    SET_ChoiceLists: (state, data) => {
      state.QuestinosChoiceLists = data
    },
    SET_ObjectLists: (state, data) => {
      state.objectLists = data
    },
    SET_Catalog: (state, data) => {
      state.catalog = data
    },
    SET_TagsList: (state, data) => {
      state.tagsList = data
    },
    SET_UserList: (state, data) => {
      state.userlist = data
    }
  },
  actions: {
    // data包含请求的页数和页码
    getChoiceLists ({ commit }, data) {
      return new Promise((resolve, reject) => {
        choice(data).then(res => {
          commit('SET_ChoiceLists', res.data.items)
          resolve(res)
        }).catch(error => {
          reject(error)
        })
      })
    },
    postChoicePublish ({ commit }, data) {
      return choicePublish(data)
    },
    // 学科列表
    getObjectsLists ({ commit }) {
      return new Promise((resolve, reject) => {
        simple().then(res => {
          commit('SET_ObjectLists', res.data)
          resolve(res)
        }).catch(err => {
          reject(err)
        })
      })
    },
    // 目录列表
    getCatalog ({ commit }) {
      return new Promise((resolve, reject) => {
        dire.simple().then(res => {
          commit('SET_Catalog', res.data)
          resolve(res)
        }).catch(err => {
          reject(err)
        })
      })
    },
    // 标签列表
    getTagsList ({ commit }) {
      return new Promise((resolve, reject) => {
        tags.simple().then(res => {
          commit('SET_TagsList', res.data)
          resolve(res)
        }).catch(err => {
          reject(err)
        })
      })
    },
    // 用户列表
    getUserList ({ commit }) {
      return new Promise((resolve, reject) => {
        users.simple({ keyword: '', disabled: 1 }).then(res => {
          commit('SET_UserList', res.data)
          console.log('userlist', res)
          resolve(res)
        }).catch(err => {
          reject(err)
        })
      })
    }
  }
}
export default questionsChoice
